<template>
    <el-container class="home-container">
        <!--        头部-->
        <el-header>
            <div>
                <img src="../../assets/img/logo.png" alt="" class="logoImg">
                <span>电商后台管理系统</span>
            </div>
            <el-button type="danger" @click="loginOut">退出登录</el-button>
        </el-header>
        <el-container>
            <!--            侧边栏-->
            <el-aside :width="isCollapse ? '64px': '200px'">
                <div class="toggle-btn" @click="toggleClick">|||</div>
<!--              router  是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转-->
                <el-menu
                        :default-active="$route.path"
                        :router="true"
                        :collapse="isCollapse"
                        :collapse-transition="false"
                        :unique-opened="true"
                        background-color="rgb(51,55,68)"
                        text-color="white"
                        active-text-color="#409BFF">
                    <!--                    一级菜单-->
                    <el-submenu :index="item.id + '' " v-for="(item,index) in menuList" :key="item.id">
                        <!--                        模板区域-->
                        <template slot="title">
                            <i :class="iconsObj[index]"></i>
                            <span>{{item.authName}}</span>
                        </template>
                        <!--                        二级菜单-->
                        <el-menu-item :index=" '/' + subItem.path" v-for="subItem in item.children" :key="subItem.id">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>{{subItem.authName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <!--            主要内容区域-->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "Home",
        data() {
            return {
                menuList: [],
                iconsObj: ["iconfont icon-users", "iconfont icon-tijikongjian", "iconfont icon-shangpin", "iconfont icon-danju", "iconfont icon-baobiao",],
                isCollapse:false
            }
        },
        created() {
            this.getMenuList()
        },
        methods: {
            loginOut() {
                window.sessionStorage.clear()
                this.$router.push('/login')
            },
            async getMenuList() {
                const res = (await this.$http.get('menus')).data
                this.menuList = res.data
            },
            // 折叠按钮
            toggleClick(){
                this.isCollapse = !this.isCollapse
            },
        }
    }
</script>

<style lang="less" scoped>
    .el-header {
        background-color: rgb(55, 63, 65);
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 10px;

        > div {
            color: white;
            font-size: 20px;
            display: flex;
            align-items: center;

            span {
                margin-left: 15px;
            }
        }
    }

    .el-aside {
        background-color: rgb(51, 55, 68);
        .el-menu{
            border-right: 0px;
        }
    }

    .el-main {
        background-color: rgb(234, 237, 241);
    }

    .home-container {
        height: 100%;
    }

    .logoImg {
        width: 50px;
        height: 50px;
    }
    .iconfont{
        margin-right: 10px;
    }
    .toggle-btn{
        background-color: rgb(74,80,100);
        color: white;
        text-align: center;
        font-size: 15px;
        line-height: 24px;
        letter-spacing: 0.2em;
        /*改变鼠标形状*/
        cursor: pointer;
    }
</style>
